package com.ruoyi.project.system.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.MedicineSimple;
import com.ruoyi.project.system.service.IMedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/medicine")
public class MedicineController {

    @Autowired
    private IMedicineService medicineService;

    /**
     * 根据科室获取药品列表
     */
    @Anonymous
    @GetMapping("/list")
    public AjaxResult getMedicineList(@RequestParam String department) {
        List<MedicineSimple> medicines = medicineService.getMedicinesByDepartment(department);
        return AjaxResult.success(medicines);
    }
    @Anonymous
    @GetMapping("/search")
    public AjaxResult searchMedicines(
            @RequestParam String department,
            @RequestParam String keyword) {
        
        Map<String, Object> params = new HashMap<>();
        params.put("department", department);
        params.put("keyword", keyword);
        
        List<MedicineSimple> medicines = medicineService.searchMedicines(params);
        return AjaxResult.success(medicines);
    }
}